package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.service.DictService;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import cn.tedu.ivos.dictoption.service.impl.DictOptionServiceImpl;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Tag(name = "字典选项模块")
@RestController
@RequestMapping("/v1/dictoption/")
public class DictOptionController {
    @Autowired
    DictOptionService dictOptionService;
    @GetMapping ("select")
    @Operation(summary = "查询字典选项信息")
    @ApiOperationSupport(order = 10)
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery){
      log.debug("查询字典选项信息dictOptionQuery={}",dictOptionQuery);
        List<DictOptionVO> list = dictOptionService.selectDictOption(dictOptionQuery);
        return JsonResult.ok(list);
    }
    @Operation(summary = "保存字典选项信息")
    @ApiOperationSupport(order = 20)
    @RequestMapping("save")
    public JsonResult saveDictOption(@Validated DictOptionSaveParam dictOptionSaveParam){
        log.debug("保存字典选项信息dictOptionSaveParam={}",dictOptionSaveParam);
        dictOptionService.saveDictOption(dictOptionSaveParam);
        return JsonResult.ok();
    }
    @Operation(summary = "删除字典选项信息")
    @ApiOperationSupport(order = 30)
    @RequestMapping("delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id){
        log.debug("删除字典选项信息id={}",id);
        dictOptionService.deleteDictOption(id);
        return JsonResult.ok();
    }
    //定义一个根据字典code查询其对应的所有字典项的方法
    @Operation(summary = "查询字典项信息")
    @ApiOperationSupport(order = 40)
    @GetMapping("select/{code}")
    public JsonResult selectDictOption(@PathVariable String code){
        log.debug( "查询字典项信息code={}",code);
        List<DictOptionVO> list = dictOptionService.selectDictOptionByCode(code);
        return JsonResult.ok(list);
    }
}
